package com.yufubao.api.controller.applet.product;

import com.yufubao.framework.annotation.SystemLog;
import com.yufubao.framework.constant.NotesConstant;
import com.yufubao.framework.result.PageUtils;
import com.yufubao.framework.result.ResponseResult;
import com.yufubao.model.dto.applet.product.SpuQueryPageDetailDto;
import com.yufubao.model.dto.applet.product.spu.SpuSaveDto;
import com.yufubao.model.pojo.applet.product.SpuInfoEntity;
import com.yufubao.service.service.applet.product.SpuInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;

/**
 * spu信息
 *
 * @author zhangzhan
 * @email 52194440@qq.com
 * @date 2024-08-29 16:01:46
 */
@Api("spu信息")
@RestController
@RequestMapping("/applet/spuinfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;

    /**
     * 商品上架并保存商户信息
     */
    @RequestMapping(value = "/{spuId}/up",method = RequestMethod.GET)
    @SystemLog(info = "商品上架并保存商户信息")
    @ApiOperation(value = "商品上架并保存商户信息", notes = NotesConstant.DEV)
    public ResponseResult up(@PathVariable("spuId") Long spuId){
        spuInfoService.up(spuId);

        return ResponseResult.ok();
    }


    /**
     * 查询当前商店的spu信息
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    //@RequiresPermissions("gulimallproduct:spuinfo:list")
    @ApiOperation(value = "查询当前商店的spu信息", notes = NotesConstant.DEV)
    @SystemLog(info = "查询当前商店的spu信息")
    public ResponseResult queryPageDetail(@RequestBody @Valid SpuQueryPageDetailDto dto){
        PageUtils page = spuInfoService.queryPageDetail(dto);

        return ResponseResult.okResultPage("page", page);
    }

    /**
     * 商家发布商品信息
     */
    @RequestMapping(value = "/saveDetail",method = RequestMethod.POST)
    //@RequiresPermissions("gulimallproduct:spuinfo:save")
    @SystemLog(info = "商家发布商品信息")
    @ApiOperation(value = "商家发布商品信息", notes = NotesConstant.DEV)
    public ResponseResult saveDetail(@RequestBody SpuSaveDto dto){
        spuInfoService.saveDetail(dto);

        return ResponseResult.ok();
    }



    /**
     * 信息
     */
    @RequestMapping(value = "/info/{id}",method = RequestMethod.GET)
    @ApiOperation(value = "信息")
    @SystemLog(info = "spu信息信息")
    public ResponseResult info(@PathVariable("id") Long id){
		SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return ResponseResult.okResultPage("SpuInfo", spuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ApiOperation(value = "保存")
    @SystemLog(info = "spu信息保存")
    public ResponseResult save(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.save(spuInfo);

        return ResponseResult.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    @ApiOperation(value = "修改")
    @SystemLog(info = "spu信息修改")
    public ResponseResult update(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.updateById(spuInfo);

        return ResponseResult.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    @ApiOperation(value = "删除")
    @SystemLog(info = "spu信息删除")
    public ResponseResult delete(@RequestBody Long[] ids){
		spuInfoService.removeByIds(Arrays.asList(ids));

        return ResponseResult.ok();
    }

}
